package com.zhxh.nzpos.sell;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.dao.GoodsDao;
import com.zhxh.nzpos.goods.GoodsItemCallBack;
import com.zhxh.nzpos.model.Goods;

/**
 * 商品列表
 * @author Administrator
 *
 */
public class DetailsFragment extends Fragment implements GoodsItemCallBack {
	public String parentId;
    private GoodsDao goodsDao;
	private ArrayList<Goods>  goods;
	private View convertView;
	private  ListView listView;
    public static DetailsFragment newInstance(String cateid) {
    	
        DetailsFragment f = new DetailsFragment();
        f.parentId = cateid;

        return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    	convertView = inflater.inflate(R.layout.goods_select_list, null);
        goodsDao = new GoodsDao(getActivity());
		goods = goodsDao.getChildScrollData(parentId, 0, 7);
        if (container == null) {
            return null;
        }

        ArrayList<String> details = new ArrayList();
        for (int i = 0; i < goods.size(); i++) {
        	details.add( goods.get(i).getName());
        }

        listView = (ListView)convertView.findViewById(R.id.goods_listview);//new ListView(getActivity());
        listView.setAdapter(new GoodsSelectListAdapter(getActivity(), goods, this));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
       

        return convertView;
    }

	@Override
	public void onDelete(String id, String name) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUpdate(String id) {
		//convertView.setVisibility(View.INVISIBLE);
		//getActivity().startActivityFromFragment(fragment, intent, requestCode)
		Toast.makeText(getActivity(), "thisis "+id, Toast.LENGTH_SHORT).show();
		
/*        View detailsFrame = getActivity().findViewById(R.id.details);
        if (detailsFrame != null) {
        	//UpdateFragment details = (UpdateFragment)getFragmentManager().findFragmentById(R.id.details);
        	//if (details == null ) {
        	UpdateFragment details = UpdateFragment.newInstance(parentId,id);

        		FragmentTransaction ft = getFragmentManager().beginTransaction();
        		ft.replace(R.id.details, details);
        		ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        		ft.commit();
        	//}
        }*/
//		Intent intent = new Intent();
//		intent.setClass(getActivity(),
//				MainActivity.class);
//
//		startActivity(intent);
		
	}
}
